home *** CD-ROM | disk | FTP | other *** search
/ Mac Easy 2010 May / Mac Life Ubuntu.iso / casper / filesystem.squashfs / usr / lib / totem / plugins / bbc / genres.py < prev    next >
Encoding:
Python Source  |  2009-04-14  |  8.5 KB  |  252 lines

  1. #!/usr/bin/python
  2. # coding=UTF-8
  3. #
  4. # Copyright (C) 2008 Tim-Philipp M√ºller <tim.muller@collabora.co.uk>
  5. # Copyright (C) 2008 Canonical Ltd.
  6. #
  7. # This program is free software; you can redistribute it and/or modify
  8. # it under the terms of the GNU General Public License as published by
  9. # the Free Software Foundation; either version 2 of the License, or
  10. # (at your option) any later version.
  11. #
  12. # This program is distributed in the hope that it will be useful,
  13. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15. # GNU General Public License for more details.
  16. #
  17. # You should have received a copy of the GNU General Public License
  18. # along with this program; if not, write to the Free Software
  19. # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301  USA.
  20. #
  21. # The Totem project hereby grant permission for non-gpl compatible GStreamer
  22. # plugins to be used and distributed together with GStreamer and Totem. This
  23. # permission are above and beyond the permissions granted by the GPL license
  24. # Totem is covered by.
  25. #
  26. # See license_change file for details.
  27.  
  28. import gobject
  29. gobject.threads_init()
  30. import pygst
  31. pygst.require ("0.10")
  32. import gst
  33.  
  34. shortref_to_label_map = {
  35.   "childrens": _("Children's"),
  36.   "childrens/activities": _("Activities"),
  37.   "childrens/drama": _("Drama"),
  38.   "childrens/entertainmentandcomedy": _("Entertainment & Comedy"),
  39.   "childrens/factual": _("Factual"),
  40.   "childrens/music": _("Music"),
  41.   "childrens/news": _("News"),
  42.   "childrens/sport": _("Sport"),
  43.   "drama": _("Drama"),
  44.   "drama/actionandadventure": _("Action & Adventure"),
  45.   "drama/biographical": _("Biographical"),
  46.   "drama/classicandperiod": _("Classic & Period"),
  47.   "drama/crime": _("Crime"),
  48.   "drama/historical": _("Historical"),
  49.   "drama/horrorandsupernatural": _("Horror & Supernatural"),
  50.   "drama/legalandcourtroom": _("Legal & Courtroom"),
  51.   "drama/medical": _("Medical"),
  52.   "drama/musical": _("Musical"),
  53.   "drama/political": _("Political"),
  54.   "drama/psychological": _("Psychological"),
  55.   "drama/relationshipsandromance": _("Relationships & Romance"),
  56.   "drama/scifiandfantasy": _("SciFi & Fantasy"),
  57.   "drama/soaps": _("Soaps"),
  58.   "drama/spiritual": _("Spiritual"),
  59.   "drama/thriller": _("Thriller"),
  60.   "drama/waranddisaster": _("War & Disaster"),
  61.   "drama/western": _("Western"),
  62.   "entertainmentandcomedy": _("Entertainment & Comedy"),
  63.   "entertainmentandcomedy/impressionists": _("Impressionists"),
  64.   "entertainmentandcomedy/satire": _("Satire"),
  65.   "entertainmentandcomedy/sitcoms": _("Sitcoms"),
  66.   "entertainmentandcomedy/sketch": _("Sketch"),
  67.   "entertainmentandcomedy/spoof": _("Spoof"),
  68.   "entertainmentandcomedy/standup": _("Standup"),
  69.   "entertainmentandcomedy/varietyshows": _("Variety Shows"),
  70.   "factual": _("Factual"),
  71.   "factual/antiques": _("Antiques"),
  72.   "factual/artscultureandthemedia": _("Arts, Culture & the Media"),
  73.   "factual/beautyandstyle": _("Beauty & Style"),
  74.   "factual/carsandmotors": _("Cars & Motors"),
  75.   "factual/cinema": _("Cinema"),
  76.   "factual/consumer": _("Consumer"),
  77.   "factual/crimeandjustice": _("Crime & Justice"),
  78.   "factual/disability": _("Disability"),
  79.   "factual/familiesandrelationships": _("Families & Relationships"),
  80.   "factual/foodanddrink": _("Food & Drink"),
  81.   "factual/healthandwellbeing": _("Health & Wellbeing"),
  82.   "factual/history": _("History"),
  83.   "factual/homesandgardens": _("Homes & Gardens"),
  84.   "factual/lifestories": _("Life Stories"),
  85.   "factual/money": _("Money"),
  86.   "factual/petsandanimals": _("Pets & Animals"),
  87.   "factual/politics": _("Politics"),
  88.   "factual/sciencenatureandenvironment": _("Science, Nature & Environment"),
  89.   "factual/travel": _("Travel"),
  90.   "learning": _("Learning"),
  91.   "learning/1119": _("Age 11-19"),
  92.   "learning/511": _("Age 5-11"),
  93.   "learning/adults": _("Adults"),
  94.   "learning/preschool": _("Pre-School"),
  95.   "music": _("Music"),
  96.   "music/classicpopandrock": _("Classic Pop & Rock"),
  97.   "music/classical": _("Classical"),
  98.   "music/country": _("Country"),
  99.   "music/danceandelectronica": _("Dance & Electronica"),
  100.   "music/desi": _("Desi"),
  101.   "music/easylisteningsoundtracksandmusicals": _("Easy Listening, Soundtracks & Musicals"),
  102.   "music/folk": _("Folk"),
  103.   "music/hiphoprnbanddancehall": _("Hip Hop, RnB & Dancehall"),
  104.   "music/jazzandblues": _("Jazz & Blues"),
  105.   "music/popandchart": _("Pop & Chart"),
  106.   "music/rockandindie": _("Rock & Indie"),
  107.   "music/soulandreggae": _("Soul & Reggae"),
  108.   "music/world": _("World"),
  109.   "news": _("News"),
  110.   "religionandethics": _("Religion & Ethics"),
  111.   "sport": _("Sport"),
  112.   "sport/archery": _("Archery"),
  113.   "sport/athletics": _("Athletics"),
  114.   "sport/badminton": _("Badminton"),
  115.   "sport/baseball": _("Baseball"),
  116.   "sport/basketball": _("Basketball"),
  117.   "sport/bowls": _("Bowls"),
  118.   "sport/boxing": _("Boxing"),
  119.   "sport/canoeing": _("Canoeing"),
  120.   "sport/cricket": _("Cricket"),
  121.   "sport/cycling": _("Cycling"),
  122.   "sport/darts": _("Darts"),
  123.   "sport/disabilitysport": _("Disability Sport"),
  124.   "sport/diving": _("Diving"),
  125.   "sport/equestrian": _("Equestrian"),
  126.   "sport/fencing": _("Fencing"),
  127.   "sport/football": _("Football"),
  128.   "sport/gaelicgames": _("Gaelic Games"),
  129.   "sport/golf": _("Golf"),
  130.   "sport/gymnastics": _("Gymnastics"),
  131.   "sport/handball": _("Handball"),
  132.   "sport/hockey": _("Hockey"),
  133.   "sport/horseracing": _("Horse Racing"),
  134.   "sport/judo": _("Judo"),
  135.   "sport/modernpentathlon": _("Modern Pentathlon"),
  136.   "sport/motorsport": _("Motorsport"),
  137.   "sport/olympics": _("Olympics"),
  138.   "sport/rowing": _("Rowing"),
  139.   "sport/rugbyleague": _("Rugby League"),
  140.   "sport/rugbyunion": _("Rugby Union"),
  141.   "sport/sailing": _("Sailing"),
  142.   "sport/shinty": _("Shinty"),
  143.   "sport/shooting": _("Shooting"),
  144.   "sport/snooker": _("Snooker"),
  145.   "sport/softball": _("Softball"),
  146.   "sport/swimming": _("Swimming"),
  147.   "sport/tabletennis": _("Table Tennis"),
  148.   "sport/taekwondo": _("Taekwondo"),
  149.   "sport/tennis": _("Tennis"),
  150.   "sport/triathlon": _("Triathlon"),
  151.   "sport/volleyball": _("Volleyball"),
  152.   "sport/waterpolo": _("Water Polo"),
  153.   "sport/weightlifting": _("Weightlifting"),
  154.   "sport/wintersports": _("Winter Sports"),
  155.   "sport/wrestling": _("Wrestling"),
  156.   "weather": _("Weather")
  157. }
  158.  
  159. # lowest = at the top
  160. shortref_to_sortrank_map = {
  161.   "news": 1,
  162.   "childrens": 2,
  163.   "drama": 3,
  164.   "entertainmentandcomedy": 4,
  165.   "factual": 5,
  166.   "learning": 6,
  167.   "music": 7,
  168.   "religionandethics": 8,
  169.   "sport": 9,
  170.   "weather": 10
  171. }
  172.  
  173. '''
  174. GenrePool: keeps track of the already-created genres, mainly so we can easily
  175.            find already-existing parents for to-be-created genres
  176. ''' 
  177. class GenrePool(object):
  178.     __slots__ = [ 'genres', 'toplevel_genres' ]
  179.  
  180.     def __init__(self):
  181.         self.clear()
  182.  
  183.     def clear(self):
  184.         self.genres = { } # maps short_ref => genre object
  185.  
  186.     def get_genre(self, short_ref):
  187.         # check if genre already exists
  188.         if short_ref in self.genres:
  189.           return self.genres[short_ref]
  190.  
  191.         # if not, create genre (and any parents which don't exist yet)
  192.         lastslash_pos = short_ref.rfind('/')
  193.         if lastslash_pos > 0:
  194.           parent_ref = short_ref[0:lastslash_pos]
  195.           gst.log('genre: ' + short_ref + ', parent_genre: ' + parent_ref)
  196.           parent = self.get_genre(parent_ref)
  197.         else:
  198.           parent = None
  199.  
  200.         genre = Genre(short_ref, parent)
  201.         self.genres[short_ref] = genre
  202.  
  203.         return genre
  204.  
  205.     def get_toplevel_genres(self):
  206.         toplevel_genres = []
  207.         for genre in self.genres.values():
  208.           if not genre.parent:
  209.             toplevel_genres.append(genre)
  210.         return toplevel_genres
  211.  
  212. '''
  213. Genre: represents a genre
  214. '''
  215. class Genre(object):
  216.     __slots__ = [ 'short_ref', 'label', 'sort_rank', 'parent',  'children', 'brands' ]
  217.  
  218.     def __init__(self, short_ref, parent_genre):
  219.         self.short_ref = short_ref
  220.  
  221.         if short_ref in shortref_to_label_map:
  222.           self.label = shortref_to_label_map[short_ref]
  223.         else:
  224.           self.label = _("Unknown: ") + short_ref
  225.  
  226.         if short_ref in shortref_to_sortrank_map:
  227.           self.sort_rank = shortref_to_sortrank_map[short_ref]
  228.         else:
  229.           self.sort_rank = 99999
  230.  
  231.         self.parent = parent_genre
  232.         self.children = []
  233.         self.brands = []
  234.  
  235.         if parent_genre is not None:
  236.           parent_genre.add_child(self)
  237.  
  238.         gst.log('created genre ' + short_ref + ' = ' + self.label)
  239.  
  240.     def add_child(self, child_genre):
  241.         if child_genre not in self.children:
  242.           self.children.append(child_genre)
  243.  
  244.     def add_brand(self, brand):
  245.         if brand not in self.brands:
  246.             self.brands.append(brand)
  247.             gst.log(self.short_ref + ': adding show ' + brand.title)
  248.  
  249. if __name__ == "__main__":
  250.   pass
  251.  
  252.